package cn.mldn.oracle.dbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class DatabaseConnection {
	
	private static final String DBDRIVER = "oracle.jdbc.driver.OracleDriver";
	private static final String DBURL = "jdbc:oracle:thin:@192.168.1.6:1521:orcl";
	private static final String DBUSER = "scott";
	private static final String PASSWORD = "tiger";
	
	private Connection connection;
	
	public DatabaseConnection(){
		try {
			Class.forName(DBDRIVER);
			this.connection = DriverManager.getConnection(DBURL, DBUSER, PASSWORD);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	public void close(){
		if (this.connection != null) {
			try {
				this.connection.close();
				System.out.println("connection has been closed.");
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
	}
	
	public Connection getConnection(){
		if (this.connection != null) {
			return this.connection;
		}
		return null;
	}
}
